package enterprise.manage.dao;

import enterprise.manage.entity.LoginLog;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.hibernate.HibernateDao;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: zhenmingyue
 * Date: 2011-7-8 10:51:22
 * Desc:
 * For :
 */
@Repository
@Transactional
public class LoginLogDao extends HibernateDao<LoginLog, Long> {
    public static final Integer INTERVAL = -30;

    public Long getloginFailedCount(String userName) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE, INTERVAL);

        Query query = this.getSession().createQuery("from LoginLog where userName = :userName and logResult = 0 and createTime > :createTime");
        query.setString("userName", userName);
        query.setDate("createTime", calendar.getTime());
        return (long) query.list().size();
    }

}
